* This script reproduces appendix material for Study 2 (Tables B3, B4, and B5)


* ------------- *
* 	TABLE B3	*
* ------------- *

use "$directory/Parallel runs/data/GB_data.dta", clear
append using "$directory/Parallel runs/data/Finland_data.dta", gen(country) force

* makes a dummy (0 = Finland, 1 = UK)
gen UK = 0 
replace UK = 1 if country == 0

* cleans and renames variables
recode gndr (1 = 0 "male") (2 = 1 "female") (9 =.), gen(female)

rename agea agerespondent

recode edulvlb (9999 5555 .a .b = .), gen(education_lvl)
label values education_lvl edulvlb

recode hincfel (9 .a .b =.), gen(feel_income)
label values feel_income hincfel

recode netusoft (9 = .), gen(netuse)
label values netuse netusoft

* estimates OLS regressions
eststo clear
eststo mc_uk: reg immigration_mc i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse if UK == 1 , rob
eststo mc_fi: reg immigrants_mc i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse if UK == 0 , rob

   
esttab mc_uk mc_fi using ///
		"$directory/Output/Table_B3.tex" ///
		, obslast gaps ar2 nonumbers nonotes se ///
		drop(0.D 0.female 0.education_lvl) ///
		addnotes("\textit{Note:} Unstandardized LPM estimates (OLS). Robust standard errors in parentheses." ///
		"\sym{\dagger} \(p<0.1)" "\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\) (two-sided tests).") ///
		title("Effect of Survey Mode on Pro-Immigration Attitudes (Study 2)") ///
		varlabels(1.D "Treatment" 1.female "Female" agerespondent "Age" c.agerespondent#c.agerespondent "Age$^2$" ///
		113.education_lvl "ISCED 1" 212.education_lvl "Gen. ISCED 2A/2B" 213.education_lvl "General ISCED 2A" ///
		222.education_lvl "Voc. ISCED 2A/2B" 229.education_lvl "Voc. ISCED 3C" 313.education_lvl "Gen. ISCED 3A" ///
		323.education_lvl "Voc. ISCED 3A" 413.education_lvl "Gen. ISCED 4A" 423.education_lvl "Voc. ISCED 4A" ///
		510.education_lvl "ISCED 5A short" 520.education_lvl "ISCED 5B" 620.education_lvl "ISCED 5A med., upper tier" ///
		720.education_lvl "ISCED 5A long, upper tier" 800.education_lvl "ISCED 6" ///
		2.feel_income "Coping on income" 3.feel_income "Diff. on income" 4.feel_income "V. diff. on income" netuse "Internet use" ///
		_cons Constant) ///
		mti("Great Britain" "Finland") ///
		replace b(%7.2f) se(%7.2f)  


* ------------- *
* 	TABLE B4	*
* ------------- *

* Open data
use "$directory/Parallel runs/data/Finland_data.dta", clear


* rename variables
recode gndr (1 = 0 "male") (2 = 1 "female") (9 =.), gen(female)
rename agea agerespondent
recode edulvlb (9999 5555 .a .b = .), gen(education_lvl)
label values education_lvl edulvlb
recode hincfel (9 .a .b =.), gen(feel_income)
label values feel_income hincfel
recode netusoft (9 = .), gen(netuse)
label values netuse netusoft
recode stfdem (99 .a .b = .), gen(SWD)
lab val SWD stfdem
recode fairelc (99 .a .b = .), gen(fair_election)
lab val fair_election fairelc
recode medcrgv (99 .a .b = .), gen(media_free)
lab val media_free medcrgv
recode rghmgpr (99 .a .b = .), gen(minority_rights)
lab val minority_rights rghmgpr
recode cttresa (99 .a .b = .), gen(impartial_courts)
lab val impartial_courts cttresa
recode implvdm (99 .a .b = .), gen(importance_democracy)
lab val importance_democracy implvdm
recode accalaw (99 .a .b = .), gen(leader_v2)
recode dfprtal (99 .a .b =.), gen(party_alternatives)
lab val party_alternatives dfprtal
recode gptpelc (99 .a .b =.), gen(gov_sanction)
lab val gov_sanction gptpelc


* Estimate and store results
eststo clear
eststo m1:  reg SWD i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m2:  reg importance_democracy i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m3:  reg leader_v2 i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m4:  reg fair_election i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m5:  reg media_free i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m6:  reg minority_rights i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m7:  reg impartial_courts i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m8:  reg party_alternatives i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m9:  reg gov_sanction i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob


esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using ///
		"$directory/Output/Table_B4.tex" ///
		, obslast gaps ar2 nonumbers nonotes se ///
		drop(0.D 0.female 0.education_lvl 1.feel_income) ///
		addnotes("\textit{Note:} Unstandardized OLS regression estimates. Robust standard errors in parentheses." ///
		"\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\) (two-sided tests).") ///
		title("Effect of Survey Mode on Democratic Attitudes (Study 2 - Finland)") ///
		varlabels(1.D "Treatment" 1.female "Female" agerespondent "Age" c.agerespondent#c.agerespondent "Age$^2$" ///
		113.education_lvl "ISCED 1" 213.education_lvl "General ISCED 2A" 313.education_lvl "General ISCED 3A" ///
		323.education_lvl "Vocational ISCED 3A" 423.education_lvl "Vocational ISCED 4A" 520.education_lvl "ISCED 5B" ///
		610.education_lvl "ISCED 5A med." 620.education_lvl "ISCED 5A med., upper tier" 710.education_lvl "ISCED 5A long" ///
		720.education_lvl "ISCED 5A long, upper tier" 800.education_lvl "ISCED 6" ///
		2.feel_income "Coping on income" 3.feel_income "Diff. on income" 4.feel_income "V. diff. on income" netuse "Internet use" ///
		_cons Constant) ///
		mti("SWD" "Import. Dem." "Strong Leader" "Fair Elec." "Media Free" "Minority Rights" "Impartial Cou" "Partisan Alt." "Punish Govt.") ///
		replace b(%7.2f) se(%7.2f)  
		
		
* ------------- *
* 	TABLE B5	*
* ------------- *

* Open data
use "$directory/Parallel runs/data/GB_data.dta", clear

* rename variables
recode gndr (1 = 0 "male") (2 = 1 "female") (9 =.), gen(female)
rename agea agerespondent
recode edulvlb (9999 5555 .a .b = .), gen(education_lvl)
label values education_lvl edulvlb
recode hincfel (9 .a .b =.), gen(feel_income)
label values feel_income hincfel
recode netusoft (9 = .), gen(netuse)
label values netuse netusoft
recode stfdem (99 .a .b = .), gen(SWD)
lab val SWD stfdem
recode fairelc (99 .a .b = .), gen(fair_election)
lab val fair_election fairelc
recode medcrgv (99 .a .b = .), gen(media_free)
lab val media_free medcrgv
recode rghmgpr (99 .a .b = .), gen(minority_rights)
lab val minority_rights rghmgpr
recode cttresa (99 .a .b = .), gen(impartial_courts)
lab val impartial_courts cttresa
recode implvdm (99 .a .b = .), gen(importance_democracy)
lab val importance_democracy implvdm
recode accalaw (99 .a .b = .), gen(leader_v2)
recode dfprtal (99 .a .b =.), gen(party_alternatives)
lab val party_alternatives dfprtal
recode gptpelc (99 .a .b =.), gen(gov_sanction)
lab val gov_sanction gptpelc

* Estimate and store results
eststo clear
eststo m1:  reg SWD i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m2:  reg importance_democracy i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m3:  reg leader_v2 i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m4:  reg fair_election i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m5:  reg media_free i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m6:  reg minority_rights i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m7:  reg impartial_courts i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m8:  reg party_alternatives i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob
eststo m9:  reg gov_sanction i.D i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl i.feel_income c.netuse, rob


esttab m1 m2 m3 m4 m5 m6 m7 m8 m9 using ///
		"$directory/Output/Table_B5.tex" ///
		, obslast gaps ar2 nonumbers nonotes se ///
		drop(0.D 0.female 0.education_lvl 1.feel_income) ///
		addnotes("\textit{Note:} Unstandardized OLS regression estimates. Robust standard errors in parentheses." ///
		"\sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\) (two-sided tests).") ///
		title("Effect of Survey Mode on Democratic Attitudes (Study 2 - GB)") ///
		varlabels(1.D "Treatment" 1.female "Female" agerespondent "Age" c.agerespondent#c.agerespondent "Age$^2$" ///
		113.education_lvl "ISCED 1" 212.education_lvl "Gen. ISCED 2A/2B" 213.education_lvl "General ISCED 2A" ///
		222.education_lvl "Voc. ISCED 2A/2B" 229.education_lvl "Voc. ISCED 3C" 313.education_lvl "Gen. ISCED 3A" ///
		323.education_lvl "Voc. ISCED 3A" 413.education_lvl "Gen. ISCED 4A" 423.education_lvl "Voc. ISCED 4A" ///
		510.education_lvl "ISCED 5A short" 520.education_lvl "ISCED 5B" 620.education_lvl "ISCED 5A med., upper tier" ///
		720.education_lvl "ISCED 5A long, upper tier" 800.education_lvl "ISCED 6" ///
		2.feel_income "Coping on income" 3.feel_income "Diff. on income" 4.feel_income "V. diff. on income" netuse "Internet use" ///
		_cons Constant) ///
		mti("SWD" "Import. Dem." "Strong Leader" "Fair Elec." "Media Free" "Minority Rights" "Impartial Court" "Partisan Alt." "Punish Govt.") ///
		replace b(%7.2f) se(%7.2f)  

		
* ------------- *
* 	FIGURE B5	*
* ------------- *

* Opens data
use "$directory/Parallel runs/data/GB_data.dta", clear

* cleans and renamer variables
recode gndr (1 = 0 "male") (2 = 1 "female") (9 =.), gen(female)
rename agea agerespondent
recode edulvlb (9999 5555 .a .b = .), gen(education_lvl)
label values education_lvl edulvlb
recode hincfel (9 .a .b =.), gen(feel_income)
label values feel_income hincfel
recode netusoft (9 = .), gen(netuse)
label values netuse netusoft
recode stfdem (99 .a .b = .), gen(SWD)
lab val SWD stfdem
recode fairelc (99 .a .b = .), gen(fair_election)
lab val fair_election fairelc
recode medcrgv (99 .a .b = .), gen(media_free)
lab val media_free medcrgv
recode rghmgpr (99 .a .b = .), gen(minority_rights)
lab val minority_rights rghmgpr
recode cttresa (99 .a .b = .), gen(impartial_courts)
lab val impartial_courts cttresa
recode implvdm (99 .a .b = .), gen(importance_democracy)
lab val importance_democracy implvdm
recode accalaw (99 .a .b =.), gen(leader_v2)
recode dfprtal (99 .a .b =.), gen(party_alternatives)
lab val party_alternatives dfprtal
recode gptpelc (99 .a .b =.), gen(gov_sanction)
lab val gov_sanction gptpelc

* makes a series of identical treatment variables (allows plotting using "coefplot"): 
gen D1 = D 
gen D2 = D 
gen D3 = D 
gen D4 = D 
gen D5 = D 
gen D6 = D
gen D7 = D
gen D8 = D
gen D9 = D


* store results
eststo clear
eststo SWD_cov: qui reg SWD i.D1 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo fair_election_cov: qui reg fair_election i.D2 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo media_free_cov: qui reg media_free i.D3 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo minority_rights_cov: qui reg minority_rights i.D4 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo impartial_courts_cov: qui reg impartial_courts i.D5 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo importance_democracy_cov: qui reg importance_democracy i.D6 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo strong_leader_cov: qui reg leader_v2 i.D7 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo alternatives_cov: qui reg party_alternatives i.D8 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob
eststo sanction_cov: qui reg gov_sanction i.D9 i.female c.agerespondent c.agerespondent##c.agerespondent i.education_lvl c.feel_income c.netuse, rob


coefplot ///
	(SWD_cov fair_election_cov media_free_cov minority_rights_cov impartial_courts_cov importance_democracy_cov strong_leader_cov alternatives_cov sanction_cov) ///
	, drop(_cons 0.D 0.female 1.female agerespondent c.agerespondent#c.agerespondent feel_income netuse 0.education_lvl ///
	113.education_lvl 212.education_lvl 213.education_lvl 222.education_lvl 229.education_lvl 313.education_lvl ///
	321.education_lvl 323.education_lvl 413.education_lvl 423.education_lvl 510.education_lvl 520.education_lvl ///
	620.education_lvl 720.education_lvl 800.education_lvl 610.education_lvl 710.education_lvl) ///
	xline(0, lcolor(gs10%75) lpattern(solid)) ///
	msymbol(O) mcolor("0 160 176") mfcolor("0 160 176") msize(medlarge) ///
	ciopts(color("0 160 176") recast(rspike)) ///
	graphregion(fcolor(white)) ///
	plotregion(lcolor(black) lwidth(med)) ///
	coeflabels( ///
	1.D1 = "Satisfaction w/ Democracy" ///
	1.D2 = "Fair Elections" ///
	1.D3 = "Free Media" ///
	1.D4 = "Minority Rights" ///
	1.D5 = "Impartial Courts" ///
	1.D6 = "Importance of Living in Democracy" ///
	1.D7 = "Strong Leader" ///
	1.D8 = "Party offer alternatives" ///
	1.D9 = "Gov. Sanction for performance" ///
	, labsize(medsmall)) ///
	title("Great Britain" ///
	, size(medium) justification(center) box bexpand margin(small)) ///
	xtitle("{bf:ATET}" "(Self-admin - Interviewer-admin)", size(medium)) ///
	xlabel(-1.5 -1 -.5 0 .5 1) ///
	name(gb_weight, replace)
	
graph export "$directory/Output/Figure_B5.pdf", as(pdf) replace	
		